package com.project.andeper.paperproject;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;

import com.wyk.greendaodemo.greendao.gen.HourData;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//按小时查询得到的数据
public class TimeDataActivity extends AppCompatActivity {
    DBManager dbManager;

    private ListView listView;
    private int queryTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_data);
        Intent intent = getIntent();
        queryTime = Integer.valueOf(intent.getStringExtra("queryTime"));
        listView = (ListView)findViewById(R.id.time_list);
        List<Map<String,Object>> list = getData();
        listView.setAdapter(new TimeDataAdapter(this,list));
    }

    public List<Map<String,Object>> getData(){
        List<Map<String,Object>> datas = new ArrayList<>();
        dbManager = DBManager.getInstance(this);

        List<HourData> hourDatas = dbManager.queryHourData(queryTime);
        for(int i = 0;i<hourDatas.size();i++){
            Map<String,Object> map = new HashMap<>();
            map.put("model",hourDatas.get(i).getModel());
            map.put("number",hourDatas.get(i).getNumber());
            map.put("info",hourDatas.get(i).getConsumption());
            datas.add(map);
        }
        return datas;
    }
}
